import { INITIAL_EXECUTE_MODAL_FORM_QUERY_VALUE } from '../../constants';
import { convertTaskStatusToText } from '@/utils/convert';
import dayjs from 'dayjs';
export default {
  name: 'ExecuteModal',
  props: {
    data: {
      type: Array,
      default: () => [],
    },
    total: {
      type: Number,
      default: 0,
    },
    pageNum: {
      type: Number,
      default: 1,
    },
    pageSize: {
      type: Number,
      default: 10,
    },
    loading: {
      type: Boolean,
      default: false,
    },
    visible: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    currentPage() {
      return this.pageNum;
    },
  },
  data() {
    return {
      formQuery: { ...INITIAL_EXECUTE_MODAL_FORM_QUERY_VALUE },
    };
  },
  methods: {
    formatTime(time) {
      return time ? dayjs(time).format('YYYY-MM-DD HH:mm:ss') : '';
    },
    formatModalStatus(status) {
      return convertTaskStatusToText(status);
    },
    onQuery() {
      const { timeRange = [] } = this.formQuery;
      this.$emit('query', { ...this.formQuery, timeRange: timeRange || [] });
    },
    onReset() {
      this.formQuery = { ...INITIAL_EXECUTE_MODAL_FORM_QUERY_VALUE };
      this.$emit('reset', { ...this.formQuery });
    },
    onDownErrorFile(row) {
      this.$emit('downErrorFile', row);
    },
    onPageSizeChange(pageSize) {
      this.$emit('pageSizeChange', { pageSize });
    },
    onPageNumChange(pageNum) {
      this.$emit('pageNumChange', { pageNum });
    },
    onClose() {
      this.$emit('close');
    },
    onOpen() {
      // 清空查询参数
      this.formQuery = { ...INITIAL_EXECUTE_MODAL_FORM_QUERY_VALUE };
      this.$emit('open');
    },
    onOK() {
      this.$emit('ok');
    },
  },
};
